﻿@model IEnumerable<FCNS.ERP.Models.ErpOrderFoodIO>

@{
    ViewBag.Title = "结单";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>@ViewBag.Title</h2>
<script src="~/Scripts/Erp/vip.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.ajaxSettings.async = false;
        var vipNOok = '';

            $(":button").click(function () {
                var m = $("#RealMoney").val();
                if (!$.isNumeric(m)) 
                {
                    alert("实收金额不能为空");
                    return;
                }
                document.location.replace("/Food/OrderEndSubmit?seatId=" +@ViewData["SeatId"]+"&money=" + m + "&vipno=" + vipNOok);
            });

            $('#vipNO').on('keypress', function (event) {
                if (event.keyCode == 13) {
                    var v = GetVip($("#vipNO").val());
                    if (v == null) {
                        $('#vipNOdetail').text("会员不存在");
                        vipNOok = '';
                    }
                    else
                    {
                        $('#vipNOdetail').text("积分：" + v.Bonus + " 折扣：" + v.Discoun);
                        $("#RealMoney").val(($("#AllMoney").val() * v.Discoun).toFixed(2));
                        vipNOok = $("#vipNO").val();
                    }
                }
            });
        });
</script>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ProductId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Count)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
    </tr>
    @{double moneySum = 0;
        bool orderCanEnd = true;
    }
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Product.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Count)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
                @{
                    moneySum += item.Count * item.Price;
                    if (item.Status != FCNS.ERP.Models.ErpOrderFoodIO.EnumOrderFoodIOstatus.上菜)
                    {
                        orderCanEnd = false;
                    }
                }
            </td>
        </tr>
                    }

</table>

<div class="form-horizontal">
    <div class="form-group">
        <label class="control-label col-md-2">合计</label>
        <div class="col-md-10">
            <input class="form-control" data-val="true" id="AllMoney" name="AllMoney" type="text" readonly="readonly" value="@moneySum" />
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">会员</label>
        <div class="col-md-10">
            <input class="form-control" data-val="true" id="vipNO" name="vipNO" type="text" />
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2"></label>
        <div class="col-md-10">
            <label class="control-label col-md-2" id="vipNOdetail"> </label>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">实收</label>
        <div class="col-md-10">
            <input class="form-control" data-val="true" id="RealMoney" name="RealMoney" type="number" value="@moneySum" min="0" />
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">支付方式</label>
        <div class="col-md-10">
            <select class="form-control" id="OrderPayType" name="OrderPayType">
                <option value="0">现金</option>
                <option value="1">微信</option>
                <option value="2">支付宝</option>
            </select>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            @{
                if (orderCanEnd)
                {
                    <button type="button" class="btn btn-default">结单</button>
                }
                else
                {
                    <h5 style="color:red;">尚有未完成的菜品</h5>
                }
            }
        </div>
    </div>
  
    </div>